package edu.byu.intex2.data.bo;

import edu.byu.intex2.data.DataException;
import edu.byu.intex2.data.dao.*;

/**
 * @author Jason Whiting
 */
public class TradeInLine extends BusinessObject
{

    private String usedCarId;
    private UsedCar usedCar;
    private String saleId;
    private Sale sale;
    private double tradeInValue;
    private int mileage;

    /**
     * Creates a new instance of BusinessObject
     * @param id
     */
    public TradeInLine(String id)
    {
        super(id);
    }//constructor


    //Quick Access Method
    public void save() throws DataException
    {
        try
        {
            TradeInLineDAO.getInstance().save(this);
        } catch (DataException e)
        {
            e.printStackTrace();
        }
    }

    /**
     * @return the tradeInValue
     */
    public double getTradeInValue()
    {
        return tradeInValue;
    }

    /**
     * @param tradeInValue the tradeInValue to set
     */
    public void setTradeInValue(double tradeInValue)
    {
        this.tradeInValue = tradeInValue;
        setDirty();
    }

    /**
     * @return the mileage
     */
    public int getMileage()
    {
        return mileage;
    }

    /**
     * @param mileage the mileage to set
     */
    public void setMileage(int mileage)
    {
        this.mileage = mileage;
        setDirty();
    }

    /**
     * @return the saleId
     */
    public String getSaleId()
    {
        return saleId;
    }

    /**
     * @param saleId the saleId to set
     */
    public void setSaleId(String saleId)
    {
        this.saleId = saleId;
        setDirty();
    }

    /**
     * @return the sale
     */
    public Sale getSale() throws Exception
    {
        if (sale == null)
        {
            sale = SaleDAO.getInstance().read(saleId);
        }
        return sale;
    }

    /**
     * @param sale the sale to set
     */
    public void setSale(Sale sale)
    {
        this.sale = sale;
        setDirty();
    }

    /**
     * @return the usedCarId
     */
    public String getUsedCarId()
    {
        if (usedCarId == null)
        {
            usedCarId = usedCar.getId();
        }
        return usedCarId;
    }

    /**
     * @param usedCarId the usedCarId to set
     */
    public void setUsedCarId(String usedCarId)
    {
        if (usedCarId == null)
        {
            usedCarId = usedCar.getId();
        }
        this.usedCarId = usedCarId;
        setDirty();
    }

    /**
     * @return the usedCar
     */
    public UsedCar getUsedCar() throws Exception
    {
        if (usedCar == null)
        {
            usedCar = UsedCarDAO.getInstance().read(usedCar.getId());
        }
        return usedCar;
    }

    /**
     * @param usedCar the usedCar to set
     */
    public void setUsedCar(UsedCar usedCar)
    {
        this.usedCar = usedCar;
        setDirty();
    }
}
